<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>四六级在线报名系统-报名页面</title>
	<link rel="stylesheet" href="layui/css/layui.css" media="all"></link>
	<link rel="stylesheet" href="layer/theme/default/layer.css" />
	<link rel="stylesheet" href="layer/mobile/need/layer.css" />

		<script src="js/jquery-3.3.1.min.js"></script>
	<script src="layui/layui.js"></script>
	<script src="layer/layer.js"></script>
</head>
<body class="layui-layout-body">
 <!--所有卡片-->
 <div id="allcord" align="center">
  <div align="center">
  <h1>查询报考资格</h1>
  </div>
  <script src="layui/layui.js"></script>
 		 <div class="demoTable">
  搜索身份证号：
  <div class="layui-inline">
    <input class="layui-input"   id="idNum"  >
  </div>
  <button class="layui-btn"  onclick="find()">搜索</button>
  		<button class="layui-btn" onclick="addexam()">添加</button>
</div>	


	<!--添加考试信息-->
		<div id="addexam" class="layer_self_wrap" style="width:500px;display:none;">
 
<!-- ID -->
				<input id="ID" type="hidden"   />
<!-- 身份证号 -->
				<div class="layui-form-item">
					<label class="layui-form-label">身份证号</label>
					<div class="layui-input-inline">
						<input id="idNumber" name="idNumber" lay-verify="required" autocomplete="off" class="layui-input" type="text" />
					</div>
				</div>
<!-- 姓名 -->
				<div class="layui-form-item">
					<label class="layui-form-label">姓名</label>
					<div class="layui-input-inline">
						<input id="userName" name="userName" lay-verify="required" autocomplete="off" class="layui-input" type="text" />
					</div>
				</div>
<!-- 学校-->
			<div class="layui-form-item">
					<label class="layui-form-label">学校</label>
					<div class="layui-input-inline">
						<input id="userEnrollmentSchool" name="userEnrollmentSchool" lay-verify="required" autocomplete="off" class="layui-input" type="text" />
					</div>
				</div>
<!-- 专业 -->
				<div class="layui-form-item">
					<label class="layui-form-label">专业</label>
					<div class="layui-input-inline">
						<input id="userEnrollmentMajor" name="userEnrollmentMajor" lay-verify="required" autocomplete="off"   type="text"  class="layui-input"     />
					</div>
				</div>
<!-- 学号-->
				<div class="layui-form-item">
					<label class="layui-form-label">学号</label>
					<div class="layui-input-inline">
						<input id="userEnrollmentNum" name="userEnrollmentNum" lay-verify="required" autocomplete="off"   type="text"  class="layui-input"     />
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block" style="margin-left: 10px;">
						<button class="layui-btn" lay-submit="" onclick="formaddSubmit()"  >提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
		 
		</div>
		
		
	<!--考生学籍信息-->
		<table class="layui-table" id="demo" lay-filter="demo"></table>
		<div id="box" style="display:none">
			<div class="layui-btn-group demoTable">
			<button class="layui-btn" data-type="getCheckData">下一步</button>
		</div>
		</div>
		
			<!--添加考试信息-->
		<div id="choicexam"   style="display: none;" align="center" >	
		<div id="addexam" class="layer_self_wrap"  >
			<div align="center">
			<h1>选择考试信息</h1>
		</div>
		
 <form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">考试信息</label>
    <div class="layui-input-block">
      <select name="exams" lay-filter="exams" id="exams">
      </select>
    </div>
  </div>
</form>
						<button class="layui-btn" lay-submit="" onclick="addinfo()"  >提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
			</div>
		</div>
		</div>
		<div>
<!--报考信息-->
		<div style="display: none;" id="exameeinfo" align="center"> 
			<h1>报考信息</h1>
		</div>
		<div id="uexamee" >
		<table class="layui-table" id="examee"   lay-filter="examee"></table>
		 </div>
		 	<script type="text/html" id="barexamee">
			<a class="layui-btn layui-btn-xs" lay-event="edit" id="edit" >去付款</a>
		</script>
		
		</div>
		
	<!--准考证信息-->
	<table class="layui-table" id="exameeprint" style="display: flex;" lay-filter="exameeprint"></table>
			<script type="text/html" id="barexameeinfo">
			<a class="layui-btn layui-btn-xs" lay-event="print" id="print">打印准考证</a>
		</script>
	
	
		<div align="left" id="idcard" style="display: none;">
			
			<table cellspacing=0 border=1 style="bordercolor:#C0C0C0;" align="center" width="80%">
　　<tr align="center" style="background:#628FC3"><td colspan="5" height="60px" width="100%" >英语四六级考生准考证</td></tr>
　　<tr align="center"><td height="100px" style="background:#92D050">考试介绍</td>
	<td colspan="4" style="background:#00B0F0">考生头像:<img id="uimg" width="100px" height="100px"></img></td></tr>　
　<tr align="center" style="background:#CBDAEB"><td height="50px" width="10%">准考证号:<span id="qnumber"></span></td>
	<td width="10%">身份证号：<span id="idnumber"></span></td>
	<td width="10%">考生姓名:<span id="uname"></span></td></tr>
　<tr align="center" style="background:#CBDAEB"><td height="50px" width="10%">考试名称:<span id="tname"></span></td>
	<td width="10%">考试时间：<span id="ttime"></span></td>
	<td width="10%">考试地点:<span id="tsite"></span></td></tr>
　　<tr align="center"><td height="50px" colspan="5" style="background:#FFC000">备注：xxxxxx</td></tr>
</table>
	 
		</div>
		
		<script src="js/config.js"></script>
 <script>
 	
 data=localStorage.getItem("cuser");
	data=JSON.parse(data);
	if(data!=null)
	{
		console.log("Welcome!")
	}
	else{
		window.location.href="login.html";
	}
 
	layui.use('table', function() {
		var table = layui.table,
			form = layui.form;
		form.on('submit(userSubmit)', function(data) {
			formSubmit(data);
			return false;
		});
	});
 
 	var idnumber,testid,userid,testsite;	
	function formaddSubmit() {
	data=localStorage.getItem("cuser");
	//data=JSON.stringify(data);
	data=JSON.parse(data);
		$.ajax({
			url: rooturl+"adduserenrollment",
			contentType: "application/json; charset=utf-8",  
		    dataType: "json",  
			type: "POST",
			async: true,
		    timeout: 5000,
			data: JSON.stringify({   
				"idNumber": $("#idNumber").val(),  
				"userEnrollmentMajor": $("#userEnrollmentMajor").val(),  
				"userEnrollmentNum": $("#userEnrollmentNum").val(),
				"userEnrollmentSchool": $("#userEnrollmentSchool").val(),
				"userName": $("#userName").val(),
				"uimg":data.ordinaryUserImg,
				"userStatus": "可以报名"
	        }),
			success: function(data) { 
				if(data.code == "1000")
					{
					layer.alert("操作成功", function() {
						layer.closeAll();
							var idnum=$("#idNumber").val();
						  findid(idnum);
						  issee()
					});
				} else {
				  layer.alert(data);
				}
			} ,
			  error: function() {
				layer.alert("操作请求错误，请您稍后再试", function() {
					layer.closeAll();
				});
			}  
		});
	}
	

function addexam() {
	layer.open({
		type: 1,
		title: "添加学籍信息",
		fixed: false,
		resize: false,
		shadeClose: true,
		area: ['550px'],
		content: $('#addexam')
	});
}
exams();
function exams() {
    $.ajax({
        url: rooturl+'examlist',
        type: 'GET',
        dataype: 'json',
        success: function (data) {
                 if (data != null) {
                 	
                       $(data.obj).each(function () {
                       	//alert(this.examinationInformationName);
                           $("#exams").append("<option value='" + this.examinationInformationID + "'>" + this.examinationInformationName + "</option>");
                       });
                      
                   }
            
        },
        error: function () {
            layer.alert('请重试');
        }
    })
}
 	
function find()
{
	var idnum=$("#idNum").val();
	$.get(rooturl+"userenrollmentidnum", {
			"idnum": idnum
		}, function(data) {
		if(data.count!=0)
		{
			findid(idnum);
			issee();
		}
		else{
		 layer.alert("无数据！请按‘添加’按钮,添加数据");
		}
		}
		);
}

function issee()
{
	var box1=document.getElementById('box');
			box1.style.display='';
		
}

function addinfo()
{
	$.ajax({
			url: rooturl+"addexamineeinfo",
			contentType: "application/json; charset=utf-8",  
		    dataType: "json",  
			type: "POST",
			async: true,
		    timeout: 50000,
			data: JSON.stringify({                     
				"idNumber": idnumber,  
				"examinationInformationID": $("#exams").val(),
				"paymentState": "未支付",
				"qenumber": RndNum(12),
				"testSite": testsite
	        }),
		success: function(data) { 
				if(data.code == "1000")
					{
					layer.alert("报名成功", function() {
						
						layer.closeAll();
						
						show();
						
					});
				} else {
				  layer.alert(data);
				}
			} ,
		 error: function() {
				layer.alert("操作请求错误，请您稍后再试", function() {
					layer.closeAll();
				});
			}  
		});
}



function RndNum(n) {
    var rnd = "";
    for (var i = 0; i < n; i++) {
        rnd += Math.floor(Math.random() * 10);
    }
    return rnd;
}

function findid(idnum)
{
	layui.use('table', function() {
	   	var table = layui.table,
			form = layui.form;
			tableIns=table.render({
				elem: '#demo',
				url: rooturl+'userenrollmentidnum?idnum='+idnum,
				id: 'idTest',
				cellMinWidth: 80,
				cols: [
					[ //表头
						{
							type: 'checkbox',
							fixed: 'left'
						},
						{
							field: 'id',
							title: 'ID',
							sort: true,
							fixed: true
						}, {
							field: 'userEnrollmentSchool',
							title: '学校' 
						},
						{
							field: 'userName',
							title: '姓名' 
						},
						{
							field: 'userStatus',
							title: '是否可以报名' 
						},
						{
							field: 'userEnrollmentNum',
							title: '学号',
							width: 200 
						}, {
							field: 'userEnrollmentMajor',
							title: '专业' 
						},
						{
							field: 'idNumber',
							title: '身份证号' 
						}  
					]
				],
				done: function(res, curr, count){
    				
     pageCurr=curr;
 }
			});
	 

		  var $ = layui.$,
			active = {
				getCheckData: function() { //获取选中数据
					//var data = obj.data;
					var checkStatus = table.checkStatus('idTest'),
					data = checkStatus.data;
					data=data.pop();
					 
					 idnumber=data.idNumber;
					 userid=data.id;
					 testsite=data.userEnrollmentSchool;
          if(data.userStatus=="可以报名")
          {
          	   var box2=document.getElementById('choicexam');
			          box2.style.display='';
          }
          else
          {
          	layer.alert("不可报名，请联系管理员！");
          }

	 
				}
			}; 
		$('.demoTable .layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
	});
}
function show()
{
	document.getElementById("exameeinfo").style.display="";
	layui.use('table', function() {
		var table = layui.table,
			form = layui.form;
			//监听单元格编辑
 
			tableIns=table.render({
				elem: '#examee',
				url: rooturl+'getbyidnum?idnum='+idnumber //数据接口
				,
				id: 'idTest',
				cellMinWidth: 80,
				cols: [
					[  
						{
							field: 'idNumber',
							title: '身份证' 
						},
						{
							field: 'qenumber',
							title: '准考证' 
						},
						{
							field: 'examinationInformationID',
							title: '考试编号',
							width: 200
						}, {
							field: 'paymentState',
							title: '支付状态',
							edit: 'text' 
						}, {
							field: 'testSite',
							title: '考试地点' 
						},{
							field: 'right' ,
							align: 'center',
							toolbar: '#barexamee'
						}
					]
				],
				done: function(res, curr, count){
    				
     pageCurr=curr;
 }
			});
			table.on('tool(examee)', function(obj) {
			
		if(obj.event === 'edit') { //编辑修改
			var datas = obj.data;
					
					$.get(rooturl+"examineeinfobyid", {
			"id": datas.id
		}, function(data) {
			if(data.code == "1000") {
	          layer.alert("付款成功！")
	          	layer.alert(datas.idNumber);
	          //localStorage.setItem("idnums",datas.idNumber);
	        //  window.location.href="exameeinfo.html";
	        print(datas.idNumber);
	        document.getElementById("allcord").style.display="none";
	   
	        document.getElementById("uexamee").style.display="none";
			} else {
				//弹出错误提示
				layer.alert(data.msg, function() {
					layer.closeAll();
					
				});
			}
		});
				
			}
		});
		$('.demoTable .layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		 
	});

}

function print(idnumber)
	{
		
	layui.use('table', function() {
		
			data=localStorage.getItem("cuser");
	//data=JSON.stringify(data);
	data=JSON.parse(data);
		idnumbers=data.idNumber;
		var table = layui.table,
			form = layui.form;
			//监听单元格编辑
			tableIns=table.render({
				elem: '#exameeprint',
				url: rooturl+'examineeinfobyidnum?idnum='+idnumbers //数据接口
				,
				id: 'idTest',
				cellMinWidth: 80
					,
				cols: [
					[ 
						{
							field: 'uName',
							title: '姓名',
					 
							sort: true,
							fixed: true
						},
						{
							field: 'uIdnumber',
							title: '身份证' 
					 
						},
						{
							field: 'qNumber',
							title: '准考证'  
						},
						{
							field: 'tName',
							title: '考试名称' 
						},
						{
							field: 'tSite',
							title: '考试地点' 
						},
						{
							field: 'tTime',
							title: '时间' 
						},{
							field: 'right',
							 
							align: 'center',
							toolbar: '#barexameeinfo'
						}
					]
				],
				done: function(res, curr, count){
    				
     pageCurr=curr;
 }
			});
			table.on('tool(exameeprint)', function(obj) {
		if(obj.event === 'print') { //编辑修改
			var data = obj.data;
			 document.getElementById("qnumber").innerText = data.qNumber;
			 document.getElementById("idnumber").innerText = data.uIdnumber;
			 document.getElementById("uname").innerText = data.uName;
			 document.getElementById("ttime").innerText = data.tTime;
			 document.getElementById("tname").innerText = data.tName;
			 document.getElementById("tsite").innerText = data.tSite;
			 document.getElementById("uimg").src = rooturl+data.uImg;
			 
			layer.open({
			type: 1,
			title: "准考证",
			fixed: false,
			resize: false,
			shadeClose: true,
			area: ['60%'],
			content: $('#idcard')
		});
			}
		});
		
		$('.demoTable .layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		 
	});
 }
 </script> 
</body>

